#ifndef SRWITHDRAWCASHAUDITWIDGET_H
#define SRWITHDRAWCASHAUDITWIDGET_H

#include <QWidget>
#include <QMap>
class QStandardItemModel;
class QTableView;
class QCheckBox;
class QLineEdit;
class QPushButton;
class QLabel;
class SRTransactionWidget;

class SRWithdrawCashAuditWidget : public QWidget
{
    Q_OBJECT

public:

    struct stTransaction{
        QString txid;
        QString vout;
        QString money;
        stTransaction(void):txid(""),
            vout(""),money(""){}
    };

    //
    struct stWithdrawCash {
        // 上笔交易
        QList<stTransaction> last_tr;
        QString info;
        // 私钥索引得到
        QString prv_idx;
        // 出账地址
        QString source_addr;
        // 目标入账地址
        QString dest_addr;
        // 转正金额
        QString dest_money;
        // 服务费
        QString tip;
        // 是否隔离验证
        QString is_verify;

        QString broadcasting;

        QString state;
        stWithdrawCash(void)
            : last_tr(),prv_idx(""),source_addr(""),
              dest_addr(""),dest_money(""),
              tip(""),is_verify(""),state("未签名"){}
    };

    struct stSignData {
        QString data;
        QString hex;
        stSignData(const QString& _data = "",
                   const QString& _hex = "")
            :data(_data), hex(_hex){}
    };



public:
    explicit SRWithdrawCashAuditWidget(QWidget *parent = 0);


    bool isBusy(void);
Q_SIGNALS:

    // 总条数 总笔数
    void sigExcelDone(int,int);

    // 成功个数 失败个数
    void sigSignDone(int,int);

    void sigSignStatus(QString, bool);

    void sigBrief(QString);

public slots:

    void onImportXlsClick(void);

    void onExportXlsClick(void);

    void onBashSignatureClick(void);

    void onTableSignModeChange(QString audit_id, bool status);

    void onStopSign(void);

    void onStopImportExcel(void);

    void onRowDoubleClicked(const QModelIndex& _item);



private Q_SLOTS:
    void onQuery(void);

private:

private:
    void threadReaderXls(QString filename);
    void threadSign(QString _mainPrvKey,
                    QMap<QString, QList<stWithdrawCash> > _mapAudit);


private:

    void saveSuccessTransaction(const QString& _auditId,
                                QList<stWithdrawCash>& _transaction);

    void insertModelData(QString audit_id, const stWithdrawCash& _data);

private:

    QLabel* labWalletName_;
    QLabel* labAuditCount_;

private:
    SRTransactionWidget* pageAuditInfo_;
    QPushButton* btnAll_;
    QLineEdit* edtAuditNum_;
    QStandardItemModel *model_;
    QTableView* tableView_;
    QMap<QString, QList<stWithdrawCash> > mapAudit_;

    QMap<QString,stSignData> mapBroadcasting_;

    std::atomic<bool> bThreadReadExcel_;
    std::atomic<bool> bThreadSign_;

    // 当前钱包种子的路径
    QString seedPath_;

};

#endif // SRWITHDRAWCASHAUDITWIDGET_H

